﻿using UnityEngine;
using System.Collections;

public delegate void OnClick(GameObject sender);

public class ClickHandler : MonoBehaviour 
{
	public OnClick 	OnPressed;
	public OnClick 	OnReleased;
	public OnClick 	OnHeld;
	public OnClick 	OnRPressed;
	public OnClick 	OnRReleased;
	public OnClick 	OnRHeld;
	public OnClick 	OnMPressed;
	public OnClick 	OnHover;

	void OnMouseDown()
	{
		if (OnPressed != null) 
			OnPressed (gameObject);
	}

	void OnMouseUp()
	{
		if (OnReleased != null) 
		{
			if (Input.GetMouseButton (0))
				OnReleased (gameObject);
		}
		if(OnRReleased != null)
		{
			if(Input.GetMouseButton(1))
				OnRReleased(gameObject);
		}
	}

	void OnMouseOver()
	{
		if (OnHover != null) 
		{
			if (Input.GetMouseButton (0))
				OnHover (gameObject);
		}	
		if (OnRPressed != null) 
		{
			if(Input.GetMouseButton(1))
				OnRPressed(gameObject);
		}
		if (OnMPressed != null) 
		{
			if(Input.GetMouseButtonDown(2))
				OnMPressed(gameObject);
		}
	}
}